<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>限时秒杀</title>
    <script src="js/jquery-3.2.1.min.js"></script>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        
        .box {
            margin: 20px auto;
            background: url("images/flash_sale.png") no-repeat;
            width: 702px;
            height: 378px;
        }
        
        .box div {
            float: left;
            width: 50px;
            height: 50px;
            border: 1px solid #ccc;
            margin-left: 5px;
            line-height: 50px;
            text-align: center;
            color: red;
            position: relative;
            top: 260px;
            left: 305px;
        }
    </style>
    <script>
        $(function() {
            //设置秒杀时间
            var endTime = new Date('2021-9-21 23:59:00');
            //返回 1970 年 1 月 1 日至今的毫秒数
            var endSeconds = endTime.getTime();
            var d = h = s = m = 0;
            //设置定时器，实现限时秒杀
            var id = setInterval(function() {
                var nowTime = new Date();
                //获取时间差，单位为秒
                var remaining = parseInt((endSeconds - nowTime.getTime()) / 1000);
                if (remaining > 0) {
                    d = parseInt(remaining / 86400);
                    h = parseInt((remaining / 3600) % 24);
                    m = parseInt((remaining / 60) % 60);
                    s = parseInt(remaining % 60);
                } else {
                    clearInterval(id);
                }
                $("#d").html(d < 10 ? '0' + d : d);
                $("#h").html(h < 10 ? '0' + h : h);
                $("#m").html(m < 10 ? '0' + m : m);
                $("#s").html(s < 10 ? '0' + s : s);
            }, 1000)

        })
    </script>
</head>

<body>
    <div class="box">
        <div id="d"></div>
        <div id="h"></div>
        <div id="m"></div>
        <div id="s"></div>
    </div>
</body>

</html>